import type { Gender } from './data';

const GenderSet: Gender[] = [
  {
    id: '-1',
    name: '全部',
    color: 'green',
    options: true,
  },
  {
    id: '0',
    name: '未知',
    color: 'green',
    options: true,
  },
  {
    id: '1',
    name: '男性',
    color: 'blue',
    options: true,
  },
  {
    id: '2',
    name: '女性',
    color: 'orange',
    options: true,
  },
];

export const GenderOptions = GenderSet.filter((o) => o.options).map((o) => ({
  id: o.id,
  name: o.name,
  color: o.color,
}));
export const GenderDefault = GenderSet.filter((o) => o.id === '0');

export const GenderParse = {
  parse: (code: string): Gender => {
    const obj = GenderSet.find((o) => o.id === code) || GenderDefault;
    return { color: '', id: '', name: '', ...obj };
  },
};
